/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.main.pojo.VO;

import com.tbit.main.constant.MachineLocationTypeConstant;
import com.tbit.main.constant.WorkOrderConstant;
import com.tbit.main.pojo.WorkOrder;
import lombok.Data;

import java.util.Objects;

/**
 * 已完成工单统计
 *
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 3.8.9.1
 * @since 2024/3/15 13:54
 */
@Data
public class WorkOrderCountRespVO {

    /**
     * 运维人员编号
     */
    private Integer accountUserId;

    /**
     * 运维人员名称
     */
    private String accountUserName;

    /**
     * 换电工单数量
     */
    private WorkOrderCount powerChangeWorkOrderCount = new WorkOrderCount();
    /**
     * 站外挪车工单数量
     */
    private WorkOrderCount outSiteMoveWorkOrderCount = new WorkOrderCount();
    /**
     * 超区挪车工单数量
     */
    private WorkOrderCount superZoneMoveWorkOrderCount = new WorkOrderCount();
    /**
     * 调度工单挪车数量
     */
    private WorkOrderCount dispatchWorkOrderCount = new WorkOrderCount();
    /**
     * 维修工单挪车数量
     */
    private WorkOrderCount repairWorkOrderCount = new WorkOrderCount();
    /**
     * 手工工单挪车数量
     */
    private WorkOrderCount labourWorkOrderCount = new WorkOrderCount();

    @Data
    static class WorkOrderCount {
        /**
         * 总数
         */
        private Integer workOrderTotal = 0;
        /**
         * 有效数量
         */
        private Integer validCount = 0;
        /**
         * 无效数量
         */
        private Integer invalidCount = 0;

        public void add(WorkOrder workOrder) {
            if (WorkOrderConstant.isValid.equals(workOrder.getIsValid())) { // 无效
                this.invalidCount++;
            }
            if (WorkOrderConstant.valid.equals(workOrder.getIsValid())) { // 有效
                this.validCount++;
            }
            this.workOrderTotal++;
        }
    }

    public void add(WorkOrderCountRespVO workOrderCountAll, WorkOrder workOrder) {
        Integer workOrderType = workOrder.getWorkType();
        Integer buildType = workOrder.getBuildType();
        Integer locationType = workOrder.getLocationType();

        if (Objects.equals(buildType, 1)) {
            if (Objects.equals(workOrderType, WorkOrderConstant.workType_HD)) { // 换电
                powerChangeWorkOrderCount.add(workOrder);
                workOrderCountAll.powerChangeWorkOrderCount.add(workOrder);
            }

            if (Objects.equals(workOrderType, WorkOrderConstant.workType_NC) && Objects.equals(locationType, MachineLocationTypeConstant.OUT_SITE_MOVE)) { // 站外
                outSiteMoveWorkOrderCount.add(workOrder);
                workOrderCountAll.outSiteMoveWorkOrderCount.add(workOrder);
            }

            if (Objects.equals(workOrderType, WorkOrderConstant.workType_NC) && Objects.equals(locationType, MachineLocationTypeConstant.SUPER_ZONE_MOVE)) { // 超区
                superZoneMoveWorkOrderCount.add(workOrder);
                workOrderCountAll.superZoneMoveWorkOrderCount.add(workOrder);
            }

            if (Objects.equals(workOrderType, WorkOrderConstant.workType_WX)) { // 维修
                repairWorkOrderCount.add(workOrder);
                workOrderCountAll.repairWorkOrderCount.add(workOrder);
            }

            if (Objects.equals(workOrderType, WorkOrderConstant.workType_DD)) { // 调度
                dispatchWorkOrderCount.add(workOrder);
                workOrderCountAll.dispatchWorkOrderCount.add(workOrder);
            }
        }

        if (Objects.equals(buildType, 2)) { // 手工
            labourWorkOrderCount.add(workOrder);
            workOrderCountAll.labourWorkOrderCount.add(workOrder);
        }

        this.accountUserId = workOrder.getGetUserId();
        this.accountUserName = workOrder.getGetUserName();
    }

}
